{% extends "base.html" %}
{% import "_macros.html" as macros %}
{% import "bootstrap/wtf.html" as wtf %}
{% block title %}helloBlog{% endblock %}
{% block page_content %}
{% block head %}
    {{ super() }}
    <link rel="stylesheet" href="{{ url_for('static', filename='css/index.css') }}">
    <script src="{{ url_for('static', filename='js/bootstrap.min.js')}}"></script>
{% endblock %}


<div class="page-header page-header-border">
    {% if current_user.is_authenticated %} <img class="img-circle center-block user-img" src="{{ current_user.gravatar(size=40) }}"> {% endif %}
    <h4 class="text-center">你好, {% if current_user.is_authenticated %}{{ current_user.username }} {% else %}少年，<a href="/auth/login">去登录</a>{% endif %}!</h4>
    {% if current_user.is_authenticated %} <div class="text-center">说说你对世界的看法,<a href="/build">去写文章</a></div> {% endif %}
</div>

<div class="post-tabs">
    <ul class="nav nav-tabs">
        <li{% if not show_followed %} class="active"{% endif %}><a href="{{ url_for('.show_all') }}" >All</a></li>
        {% if current_user.is_authenticated %}
        <li{% if show_followed %} class="active"{% endif %}><a href="{{ url_for('.show_followed') }}">Followers</a></li>
        {% endif %}
    </ul>
    <div class="container">
        <div class="row">
            <div class="col-md-8">
                <div id="postlist">
                    {% if posts %}
                        {% for post in posts %}
                            <div class="panel posts-list">
                                <div class="panel-heading">
                                    <div class="text-center">
                                        <div class="row">
                                            <div class="col-sm-9">
                                                <h3 class="pull-left">{{post.title}}</h3>
                                            </div>
                                            <div class="col-sm-3">
                                                <h4 class="pull-right">
                                                <small>{{ moment(post.timestamp).fromNow() }}</small>
                                                </h4>
                                            </div>
                                        </div>
                                    </div>
                                    <div>
                                        <a href="{{ url_for('.user', username=post.author.username) }}">
                                            <img class="img-rounded profile-thumbnail" src="{{ post.author.gravatar(size=20) }}">
                                            {{post.author.username}}
                                        </a>
                                    </div>
                                </div>
                                <div class="panel-body">
                                    {% if post.body_html %}
                                        {{ post.body_html | safe }}
                                    {% else %}
                                        {{ post.body }}
                                    {% endif %}

                                </div>
                                <div class="panel-footer posts-list-footer">
                                    {% if current_user == post.author %}
                                        <a href="{{ url_for('.edit', id=post.id) }}">
                                            <span class="label label-color">Edit</span>
                                        </a>
                                        {% elif current_user.is_administrator() %}
                                        <a href="{{ url_for('.edit', id=post.id) }}">
                                            <span class="label label-danger">Edit [Admin]</span>
                                        </a>
                                    {% endif %}
                                     <a href="{{ url_for('.post', id=post.id) }}">
                                         <span class="label label-color">查看详情</span>
                                     </a>
                                     <a href="{{ url_for('.post', id=post.id) }}#comments">
                                        <span class="label label-color">{{ post.comments.count() }} Comments</span>
                                    </a>
                                </div>
                            </div>
                        {% endfor %}
                    {% endif  %}
            </div>
                <div class="pagination">
                    {{ macros.pagination_widget(pagination,'.index')}}
                </div>
            </div>
            {% if current_user.is_authenticated %}
                <div class="col-md-4 post-author" >
                    <h2 class="sidebar-heading">About Me</h2>
                        <h1>{{ current_user.username }}</h1>
                        {% if current_user.name or current_user.location %}
                            <p>
                                {% if current_user.name %}{{ current_user.name }}{% endif %}
                                {% if current_user.location %}
                                    From <a href="https://www.amap.com/search?query={{ current_user.location }}">
                                        {{ current_user.location }} </a>
                                {% endif %}
                            </p>
                        {% endif %}
                        {% if current_user.about_me %}
                            <p>{{ current_user.about_me }}</p>
                        {% endif %}
                        <p> Member since {{ moment(current_user.member_since).format('L') }} Last seen {{ moment( current_user.last_seen).fromNow() }}. </p>
                </div>
            {% endif %}
        </div>
    </div>

</div>
<div>

</div>


{% endblock %}